import React from 'react';
import _ from 'lodash';
import McTable from './Table';

let HocMcTable = (option) => WrapperComponent => {
    let defaultOption = {
        isFixHeader: false,
        resizeAble: false,
        disableLoad: false,
        hidePagination: false,
        firstDisplayColumns: [],
        isCrossPageSelect: false,
        doNotClearSelection: false,
        searchKey: 'keyword',
    }

    option = Object.assign(defaultOption, option);
    if (option.doNotClearSelection) option.isCrossPageSelect = true;
    let defaultPageSizeOptions = [10, 20, 50, 100];
    if (option.pageSize && defaultPageSizeOptions.indexOf(option.pageSize) < 0) {
        defaultPageSizeOptions.push(option.pageSize);
        defaultPageSizeOptions.sort((a, b) => { return a - b });
    }
    _.forEach(defaultPageSizeOptions, (val, index) => {
        defaultPageSizeOptions[index] = val + '';
    });

    /**!SECTION
     * 
     * generateColumnSet(自定义展示列)
     */
    return function WrappedComponent() {

        const generateTable = () => {
            return <McTable>
                </McTable>
        }

        const generateFilter = () => {

        }

        const generateSearch = () => {

        }

        const dataFetch = () => {

        }

        const setColumns = () => {
            
        }

        const setDataFetchFn = () => {
            
        }

        return <WrapperComponent
                generateTable = {generateTable}
                generateFilter={generateFilter}
                generateSearch={this.generateSearch}
                dataFetch={this.dataFetch}
                setColumns={this.setColumns}
                setDataFetchFn={this.setDataFetchFn}>
        </WrapperComponent>;
    }
}